package com.simple.chiralium.upms.biz.controller;

import com.simple.chiralium.common.core.annotion.operationLogger.OperationLogger;
import com.simple.chiralium.common.core.util.Result;
import com.simple.chiralium.upms.api.entity.SysMenu;
import com.simple.chiralium.upms.biz.service.SysMenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统菜单Controller
 *
 * @author SimpleZzz
 * @date 2021/12/08 11:13:20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/menu")
public class SysMenuController {

    /**
     * 菜单权限service
     */
    private final SysMenuService sysMenuService;

    /**
     * 查询所有菜单
     *
     * @return {@link Result}<{@link List}<{@link SysMenu}>>
     */
    @GetMapping
    @OperationLogger
    public Result<List<SysMenu>> findAll(){
        return Result.ok(sysMenuService.list());
    }

    /**
     * 根据id查询菜单
     *
     * @param id id
     * @return {@link Result}<{@link SysMenu}>
     */
    @GetMapping("/{id}")
    public Result<SysMenu> getById(@PathVariable String id){
        return Result.ok(sysMenuService.getById(id));
    }

    /**
     * 更新菜单
     *
     * @param sysMenu 系统菜单
     * @return {@link Result}
     */
    @PutMapping
    public Result<Object> updateMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.updateMenu(sysMenu);
        return Result.ok();
    }

    /**
     * 添加菜单
     *
     * @param sysMenu 系统菜单
     * @return {@link Result}
     */
    @PostMapping
    public Result<Object> addMenu(SysMenu sysMenu){
        sysMenuService.save(sysMenu);
        return Result.ok();
    }

    /**
     * 删除菜单
     *
     * @param id id
     * @return {@link Result}
     */
    @DeleteMapping("/{id}")
    public Result<Object> deleteMenu(@PathVariable String id){
        sysMenuService.removeById(id);
        return Result.ok();
    }
}
